<template>
  <!--  展厅立项-->
  <div>
    <searchData
        :search-data="searchArr"
        :refreshCom="true"
        :isExpand="true"
        :row-count="6"
        @search="search"
    />

    <a-card :bordered="false">
      <b-table
          ref="table"
          class="m-table"
          size="default"
          :scroll="{x: 1500, y: 'calc(50vh)' }"
          :exportConfig="{ use: true,select: '展厅立项-导出选中',all: '展厅立项-导出全部'}"
          :exportConfigText="{ select: '导出选中',all: '导出全部'}"
          :selectConfig="{use: true, type: 'checkbox',rowKey: 'id' }"
          :out-selected-row-keys.sync="outSelectedRowKeys"
          :rowKey="record => record.id"
          :columns="tabColumnsCreate"
          :request="loadData"
          :alert="true"
          show-size-changer
          show-quick-jumper
          showPagination="auto"
      >
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <!-- 按钮-->
        <router-link slot="prefix" :to="{name:'AssetImport'}">
          <a-button
              v-btn-permission="'dc_005_add_01'"
              type="primary">
            立项
          </a-button>
        </router-link>
        <a-popconfirm
            slot="prefix"
            :title="'确定要去除'+outSelectedRowKeys.length + '条数据吗(不可恢复)?'" @confirm="() => handleRemove()">
          <a-button
              v-btn-permission="'dc_005_del_01'"
              type="primary"
              :loading="deleteLoading"
              :disabled="outSelectedRowKeys.length == 0">删除
          </a-button>
        </a-popconfirm>

        <span slot="operation" slot-scope="text, record">
                <a  v-btn-permission="'dc_005_loo_01'"
                    @click="toDetail(record)">查看</a>
                <span>
                  <a-divider type="vertical"/>
                  <a v-btn-permission="'dc_005_edi_01'" @click="editRecord(record)">编辑</a>
                </span>
        </span>
      </b-table>
    </a-card>

  </div>
</template>

<script>
import OrgTreeSelect from '@/components/OrgTreeSelect'
import {getProjectsList} from "@/api/project/projects";
import {tabColumnsCreate} from "../model.js";
import {list, deleteSetUpInfoBatch} from "@/api/material/assets/assetManage";

export default {
  name: 'AssetCreate',
  data() {
    return {
      tabColumnsCreate,
      deleteLoading: false,
      outSelectedRowKeys: [],
      queryParam: {},
      searchArr: [
        {
          name: '所属单位',
          // value: 'orgId',
          valueKey: 'org',
          type: OrgTreeSelect,
          isNeedAuth: false
        },
        {
          name: '立项时间',
          value: 'createTime',
          type: 'dateRangeFormat'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        let query = Object.assign({}, {pageNum: parameter.pageNo, pageSize: parameter.pageSize, param: this.queryParam})
        return list(query).then((res) => {
          return {
            code: 200,
            // ...res.data,
            data: res.data.list,
            currentPage: res.data.pageNum,
            totalSize: res.data.total,
            totalPage: res.data.firstPage
          }
        })
      },
    }
  },
  methods: {
    search(val) {
      this.queryParam = {setUpTimeStart: val.createTimeStart, setUpTimeEnd: val.createTimeEnd, ...val.org}
      this.$refs.table.refresh()
    },
    toDetail(item) {
      this.$router.push({
        name: 'AssetDetail',
        query: {
          id: item.id,
          isEdit: 0
        }
      })
    },
    editRecord(item) {
      this.$router.push({
        name: 'AssetDetail',
        query: {
          id: item.id,
          isEdit: 1
        }
      })
    },
    handleRemove() {
      let toDelete = this.outSelectedRowKeys
      this.deleteLoading = true
      deleteSetUpInfoBatch(toDelete).then(res => {
        this.deleteLoading = false
        if(res.code==='0'){
          this.$message.success('删除成功')
          this.$refs.table.refresh(true)
        } else {
          this.$message.success('删除失败')
        }
      }).catch((e) => {
        this.$message.success('删除失败')
        this.deleteLoading = false
      })
    }
  }
}

</script>


<style scoped lang="less">
.m-table /deep/ .ant-table-body {
  min-height: 50vh;
}

/deep/ .m-table .ant-table-tbody > tr > td {
  height: 50px;
}
//调整head行属性
/deep/ .m-table .ant-table-thead > tr > th {
  height: 50px;
}
</style>